import 'package:casdon/core/logger/log.dart';
import 'package:casdon/core/network/business_exception.dart';
import 'package:casdon/modules/me/data/api/service_order_api.dart';
import 'package:casdon/modules/me/data/repository/me_repository.dart';
import 'package:casdon/modules/me/data/repository/me_repository_impl.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class ServiceOrderUsecase {
  final MeRepository _repository;

  const ServiceOrderUsecase(this._repository);

  Future<ResponseServiceOrderDataApi?> execute(String reqId) async {
    try {
      var ret = await _repository.getServiceOrderList(reqId: reqId);
      return ret;
    } on BusinessException {
      rethrow;
    } catch (e) {
      Log.e("ServiceOrderUsecase 失败", e.toString(), StackTrace.current);
      throw Exception("ServiceOrderUsecase 失败");
    }
  }
}

final serviceOrderUsecaseProvider = Provider(
  (ref) => ServiceOrderUsecase(ref.read(meRepositoryProvider)),
);
